package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * TODO
 *
 * @Author Yjr
 * @Date 2025/6/21 15:24
 */
@Configuration
public class TopicConfig {
    /**
     * 创建交换机
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
//        return new TopicExchange("hmall.topic");
        return ExchangeBuilder.topicExchange("hmall.topic").build();
    }

    /**
     * 创建消费者队列1
     * @return
     */
    @Bean
    public Queue queue1(){
//        return new Queue("topic.queue1");
        return QueueBuilder.durable("topic.queue1").build();
    }

    /**
     * 创建消费者队列2
     * @return
     */
    @Bean
    public Queue queue2(){
//        return new Queue("topic.queue2");
        return QueueBuilder.durable("topic.queue2").build();
    }

    /**
     * 绑定队列1
     * @param queue1
     * @param topicExchange
     * @return
     */
    @Bean
    public Binding bindingQueue1(Queue queue1,TopicExchange topicExchange){
        return BindingBuilder.bind(queue1).to( topicExchange).with("china.#");

    }

    /**
     * 绑定队列2
     * @param queue2
     * @param topicExchange
     * @return
     */
    @Bean
    public Binding bindingQueue2(Queue queue2,TopicExchange topicExchange){
        return BindingBuilder.bind(queue2).to( topicExchange).with("*.news");

    }
}
